var express = require('express');
var router = express.Router();
var mysql = require('mysql');
const {
  mysqlCreate
} = require('./utils');

//连接数据库
let conn = mysqlCreate();

//发送新文章
router.post('/', (req, res) => {
  conn = mysql.createConnection(conn.config);
  const {
    id,
    title,
    content,
    user,
    type
  } = req.body;
  var sql = `UPDATE article SET title = '${title}', content = '${content}', user = '${user}', type = '${type}' WHERE id='${id}'`
  conn.connect();
  conn.query(sql, function (err, result) {
    if (err) {
      res.json({
        code: -1,
        message: "插入失败"
      })
    } else {
      res.json({
        code: 10000,
        message: "OK"
      })
    }
  })
  conn.end();
})


module.exports = router;
